package com.chen.facemanager;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.assertj.core.util.Maps;
import org.junit.Test;

import java.util.*;

/**
 * @ClassName T3
 * @Description
 * @Author Mr-CHEN
 * @Date 2019/9/5 0005 10:31
 * @Version V1.0
 **/

public class T3 {

    @Test
    public void list(){
        List<String> names = null;
//        names.forEach(s -> System.out.println(s));
        Optional.ofNullable(names).orElse(Collections.emptyList())
                .forEach(s -> System.out.println(s));
    }

    @Test
    public void string(){
        String name = "cc";
//        names.forEach(s -> System.out.println(s));
        String a = Optional.ofNullable(name).orElse("a");
        System.out.println(a);
    }

    @Test
    public void map(){
        Map<String,Object> names = null;
        Map<String, Object> stringObjectMap = Optional.ofNullable(names).orElse(Maps.newHashMap("a", "ccc"));
        System.out.println(stringObjectMap.get("a"));
    }

    @Test
    public void obj(){
        Student student = null;
        Student student1 = Optional.ofNullable(student).orElse(new Student(1, "cc"));
        System.out.println(student1.getName());
    }
}

@Data
@AllArgsConstructor
class Student{
    private int id;
    private String name;
}